import {
  ApiResponse,
  http as api,
  ListResponse,
  SearchKeyQueryParam,
  LoginAccountResponse,
} from 'slash-admin';

export interface authTbUserResponse {
  id: string;
  fkDeptCode: string;
  nickName: string;
  username: string;
  phone: string;
  idCard: string;
  email: string;
  sex: number;
  account: string;
  loginPassword: string;
  operatePassword: string;
  salt: string;
  fkPostId: string;
  isLock: number;
  accountType: string;
  headImgAddress: string;
  deleted: string;
  createTime: string;
  updateTime: string;
  createUserAccount: string;
  updateUserAccount: string;
}

export interface SelectauthTbUserPageListQueryParam extends SearchKeyQueryParam {}

/**
 * 分页查询列表
 * @param query
 */
export const selectPageList = (
  query: SelectauthTbUserPageListQueryParam
): Promise<ListResponse<authTbUserResponse>> => {
  return api.doGet('/AuthApp/authTbUser/selectPageList', query);
};
/**
 * 根据ID查询
 * @param id
 */
export const selectById = (id: string | number): Promise<ApiResponse<authTbUserResponse>> => {
  return api.doGet('/AuthApp/authTbUser/selectById', { id: id });
};

/**
 * 根据phone查询
 * @param phone
 */
export const selectByPhone = (phone: string): Promise<ApiResponse<authTbUserResponse>> => {
  return api.doGet('/AuthApp/authTbUser/selectByPhone', { phone: phone });
};
/**
 * 根据account查询
 * @param account
 */
export const selectByAccount = (account: string): Promise<ApiResponse<authTbUserResponse>> => {
  return api.doGet('/AuthApp/authTbUser/selectByAccount', { account: account });
};

/**
 * 新增
 * @param data
 */
export const doSaveEntity = (data: any): Promise<ApiResponse<boolean>> => {
  return api.doPost('/AuthApp/authTbUser/save', data);
};
/**
 * 实体
 * @param data
 */
export const doUpdateEntity = (data: any): Promise<ApiResponse<boolean>> => {
  return api.doPost('/AuthApp/authTbUser/update', data);
};
/**
 * 逻辑删除
 * @param id|ids
 */
export const doLogicDeleteEntity = (
  ids: Array<string | number> | number | string
): Promise<ApiResponse<boolean>> => {
  let data: any = null;
  if (Array.isArray(ids)) {
    data = ids;
  } else {
    data = [ids];
  }
  return api.doPost('/AuthApp/authTbUser/logicDelete', data);
};
/**
 * 物理删除
 * @param id|ids
 */
export const doDeleteEntity = (
  ids: Array<string> | number | string
): Promise<ApiResponse<boolean>> => {
  let data: any = null;
  if (Array.isArray(ids)) {
    data = ids;
  } else {
    data = [ids];
  }
  return api.doPost('/AuthApp/authTbUser/delete', data);
};
export const doUploadHeadImg = async (data: [any], uploadPath?: string) => {
  const formData = new FormData();
  for (const it of data) {
    formData.append('file', it);
  }
  formData.append('uploadPath', 'user/headImg');
  return api.doUpload(null, formData);
};
/**
 * 修改密码
 * @param data
 * @returns
 */
export const doModifyPassword = (data: any): Promise<ApiResponse<LoginAccountResponse>> => {
  return api.doPost('/AuthApp/user/modifyPassword', data);
};
/**
 * 获取所有数据权限
 */
export const fetchAllDataPermssion = (searchKey: string) => {
  return api.doGet('/AuthApp/DataPermissions/selectAllDataPermissionObject', { searchKey });
};
/**
 * 批量配置用户信息
 * @param data
 */
export const doBatchSimpleUpdate = (
  authTbUserSimple: any,
  userIdList: string[]
): Promise<ApiResponse<boolean>> => {
  return api.doPost('/AuthApp/authTbUser/batchSimpleUpdate', {
    authTbUserSimple,
    userIdList,
  });
};

/**
 * 用户解锁
 * @param userIds
 * @returns
 */
const doUnlockUser = (userIds: string[]): Promise<ApiResponse<boolean>> => {
  return api.doPost('/AuthApp/authTbUser/unlockUser', userIds);
};
export default {
  doUploadHeadImg,
  selectPageList,
  selectById,
  doDeleteEntity,
  doLogicDeleteEntity,
  doUpdateEntity,
  doSaveEntity,
  selectByPhone,
  selectByAccount,
  fetchAllDataPermssion,
  doBatchSimpleUpdate,
  doUnlockUser,
};
